define(
	[
		'require'
	],
	function(require){
		var that;
		var Controller = Ember.Controller.extend({
				needs: ["businessDetail", "businessCenter","businessOverview"],

				business: Ember.computed.alias('controllers.businessDetail.model'),

				pinTimePoint: Ember.computed.alias('controllers.businessDetail.pinTimePoint'),

				clickTimePoint: Ember.computed.oneWay('controllers.businessDetail.clickTimePoint'),

						initTime: function(){
			        var ctrl = this;
			        var startDate = ctrl.get("startDate");
			        var endDate = ctrl.get("endDate");
			        if(this.get("clickTimePoint") != null ){
			        	var date = new Date(this.get("clickTimePoint"));
			        	ctrl.set("endDate",new Date(+date+60000));
			        	if((isNaN(startDate))){
			        		ctrl.set("startDate",new Date(+date+60000)-60000);
			        	}else{
			        		ctrl.set("startDate",new Date(+date+60000)-(Math.abs(+endDate-(+startDate))));
			        	}
			        	
			        	
			        	setTimeout(function(){
			        		var startDate = APM.util.formatDate(new Date(+ctrl.get("startDate")), "yyyy/MM/dd H:mm");
			        		var endDate = APM.util.formatDate(new Date(+ctrl.get("endDate")), "yyyy/MM/dd H:mm");
			        		$('#config-demo').val(startDate+' - '+endDate);
			        	});
			        	
			        }else{
			        	var sdate = new Date(new Date() - timeD_value - 60000-60000);
				        sdate.setSeconds(0);
				        sdate.setMilliseconds(0); 
				        ctrl.set("startDate",new Date(+sdate));
				        var edate = new Date(new Date() - timeD_value-60000);
				        edate.setSeconds(0);
				        edate.setMilliseconds(0); 
				        ctrl.set("endDate",new Date(+edate));
			        }
			    },
				difference: "60000",

				

				objectBase:{
					"typeName":'',
					"channelName":'',
					"dstIp":'',
					"srcIp":'',
					"responseCode": '',
					"groupBy": ''
				},

				dimension:1,

				pageTop:10,

				miltListsShow: {	
					"dimensionOne": false,
					"dimensionRadioOne":true,
					"dimensionTwo": false,
					"dimensionRadioTwo":false,
					"dimensionThree": false,
					"dimensionRadioThree":false,
					"dimensionFour": false,
					"dimensionRadioFour":false,
					"dimensionFive": false,
					"dimensionRadioFive":false
				},

				selectTop1: Ember.A([{"name":"Top10","id":"oneTop10"},{"name":"Top50","id":"oneTop50"},{"name":"全部","id":"oneTopAll"}]),
				selectTop2: Ember.A([{"name":"Top10","id":"twoTop10"},{"name":"Top50","id":"twoTop50"},{"name":"全部","id":"twoTopAll"}]),
				selectTop3: Ember.A([{"name":"Top10","id":"threeTop10"},{"name":"Top50","id":"threeTop50"},{"name":"全部","id":"threeTopAll"}]),
				selectTop4: Ember.A([{"name":"Top10","id":"fourTop10"},{"name":"Top50","id":"fourTop50"},{"name":"全部","id":"fourTopAll"}]),
				selectTop5: Ember.A([{"name":"Top10","id":"fiveTop10"},{"name":"Top50","id":"fiveTop50"},{"name":"全部","id":"fiveTopAll"}]),

				multColumns: [
					{
						headerText: "序号",
						dataKey:"sequence",
						width: 60,
						allowSort: false,
						ensurePxWidth: true,
						
					},
					{
						headerText: "交易类型",
						dataKey:"typeName",
						textAlignment:"left",
						allowSort: false,
						cellFormatter: function (args, colume) {
							if (args.row.type & $.wijmo.wijgrid.rowType.data) {							
								var data = args.row.data;

								if(data["channelName"]){
									colume.headerText = "交易渠道";
									var value = args.row.data.channelName;
								}else if(data["responseCode"]){
									colume.headerText = "交易返回码"
									var value = args.row.data.responseCode;
								}else if(data["dstIp"]){
									colume.headerText = "服务器IP"
									var value = args.row.data.dstIp;
								}else if(data["srcIp"]){
									colume.headerText = "客户端IP"
									var value = args.row.data.srcIp;
								}else{
									colume.headerText = "交易类型"
									var value = args.row.data.typeName;
								}
								
								args.$container
									.attr("title",value)
									.addClass("btn-link mult-height")
									.css("text-overflow", "ellipsis")
									.append(APM.util.escape(value));
								return true;
							}
						}
					},
					{
						headerText: "交易笔数",
						allowSort: false,
						dataKey:"id",
						textAlignment:"right",
						cellFormatter:function(args){
							if (args.row.type & $.wijmo.wijgrid.rowType.data) {
								var data = args.row.data.id;
								if(data == 0){
									data = 0;
								}else if(!data){
									data = "-";
								}

								var dimension = args.row.data.dimension;

								$(".dimensionNum").eq(dimension-1).find("th").eq(2).on("click",function(){
									that.set("changeString",true);
									that.set("pageDimension",dimension);
									that.selectedDimensionToString(dimension);
									that.set("sortBy","id");
								});
								var cb = $("<div></div>").text(data);
								cb.appendTo(args.$container);
								return true;
							}
						}
					},
					{
						headerText: "交易成功率%",
						allowSort: false,
						textAlignment:"right",
						dataKey:"business/success/rate",
						cellFormatter:function(args){
							if (args.row.type & $.wijmo.wijgrid.rowType.data) {
								var data = args.row.data["business/success/rate"];
								if(data == 0){
									data = 0;
								}else if(!data){
									data = "-";
								}
								var dimension = args.row.data.dimension;
								$(".dimensionNum").eq(dimension-1).find("th").eq(3).on("click",function(){
					
									that.set("changeString",true);
									that.set("pageDimension",dimension);
									that.selectedDimensionToString(dimension);
									that.set("sortBy","successRate");
									
								});;
								var cb = $("<div></div>").text(data);
								cb.appendTo(args.$container);
								return true;
							}
						}
					},
					{
						headerText: "响应时间",
						allowSort: false,
						dataKey:"responseTime",
						textAlignment:"right",
						cellFormatter:function(args){
							if (args.row.type & $.wijmo.wijgrid.rowType.data) {
								var data = args.row.data.responseTime;
								if(data == 0){
									data = 0;
								}else if(!data){
									data = "-";
								}
								var dimension = args.row.data.dimension;
								$(".dimensionNum").eq(dimension-1).find("th").eq(4).on("click",function(){
					
									that.set("changeString",true);
									that.set("pageDimension",dimension);
									that.selectedDimensionToString(dimension);
									that.set("sortBy","responseTime");
									
								});

								var cb = $("<div></div>").text(APM.util.indicatorFormatter("transform_time")(data));
								cb.appendTo(args.$container);
								return true;
							}
						}
						
					}
				],
				selectedDimensionToString:function(dimension){
					var ctrl = this;

					switch(dimension){
							case 1:
								var oneString = ctrl.get("oneString1");
								ctrl.setString(oneString);
							break;
							case 2:
								var twoString = ctrl.get("twoString1");
								ctrl.setString(twoString);
							break;
			
							case 3:
								var threeString = ctrl.get("threeString1");
								ctrl.setString(threeString);
							break;
							case 4:
								var fourString = ctrl.get("fourString1");
								ctrl.setString(fourString);
							break;
							case 5:
								var fiveString = ctrl.get("fiveString1");
								ctrl.setString(fiveString);
							break;
						}
				},

				setString: function(string){

					if(!string){
						return;
					}

					var ctrl = this;
					ctrl.set("typeName",string["typeName"]||"");
					ctrl.set("channelName",string["channelName"]||"");
					ctrl.set("dstIp",string["dstIp"]||"");
					ctrl.set("srcIp",string["srcIp"]||"");
					ctrl.set("responseCode",string["responseCode"]||"");
					ctrl.set("groupBy",string["groupBy"]||"");
				},
				multContent: Ember.A([]),

				//观察sortBy变化做请求

				sortByChange: Ember.observer("sortBy",function(){
				
					if(!this.get("sortBy")){
						return;
					}

					Ember.run.once(this,"headSort");
					
				}),
				headSort: function(){

					var pageDimension = this.get("pageDimension"),
						ctrl = this;
					switch(pageDimension){
						case 1:
							ctrl.set("desc",ctrl.get("descGroup")["one"][ctrl.get("sortBy")]);
						break;
						case 2:
							ctrl.set("desc",ctrl.get("descGroup")["two"][ctrl.get("sortBy")]);
						break;
						case 3:
							ctrl.set("desc",ctrl.get("descGroup")["three"][ctrl.get("sortBy")]);
						break;
						case 4:
							ctrl.set("desc",ctrl.get("descGroup")["four"][ctrl.get("sortBy")]);
						break;
						case 5:
							ctrl.set("desc",ctrl.get("descGroup")["five"][ctrl.get("sortBy")]);
						break;
					}
					this.requireData();
					
				},
				//通过维度来跟换传给后台的string;
				
				upDataString: function(index){
					var ctrl = this;
					var json ;

					switch(index){
						case 1:
							json = ctrl.get("oneString1");
						break;
						case 2:
							json = ctrl.get("twoString1");
						break;
						case 3:
							json = ctrl.get("threeString1");
						break;
						case 4:
							json = ctrl.get("fourString1");
						break;
						case 5:
							json = ctrl.get("fiveString1");
						break;
					}

					for(var name in json){
						if(name == "typeName"){
							ctrl.set("typeName",json[name]);
						}else if(name == "channelName"){
							ctrl.set("channelName",json[name]);
						}else if(name == "dstIp"){
							ctrl.set("dstIp",json[name]);
						}else if(name == "responseCode"){
							ctrl.set("responseCode",json[name]);
						}else if(name == "srcIp"){
							ctrl.set("srcIp",json[name]);
						}else if(name == "groupBy"){
							ctrl.set("groupBy",json[name]);
						}
					}

				},

				selectCodeExtraction: function(currentValue){
					var ctrl = this,
						typeName = null,
						channelName = null,
						dstIp = null,
						srcIp = null,
						responseCode = null,
						groupBy = null,
						ctrl = this,
						json = null,
						index = null;

					ctrl.set("desc",true);

					if(ctrl.get("shieldingWithSavedData")){
						return;
					}

					if(currentValue.indexOf("one") != -1){
						index = 1;
					}else if(currentValue.indexOf("two") != -1){
						index = 2;
					}else if(currentValue.indexOf("three") != -1){
						index = 3;
					}else if(currentValue.indexOf("four") != -1){
						index = 4;
					}else if(currentValue.indexOf("five") != -1){
						index = 5;
					}

					ctrl.upDataString(index);


					if(currentValue.indexOf("10") != -1){
						ctrl.set("pageTop",10);
					}else if(currentValue.indexOf("50") != -1){
						ctrl.set("pageTop",50);
					}else if(currentValue.indexOf("All") != -1){
						ctrl.set("pageTop",1);
					}
					

					ctrl.requireData();
				},

				//观察下拉框的value值设置pageSize段来重庆请求接口

				currentValue1Change: Ember.observer("currentValue1",function(){

					var currentValue = this.get("currentValue1");

					this.selectCodeExtraction(currentValue);	
				}),

				currentValue2Change: Ember.observer("currentValue2",function(){

					var currentValue = this.get("currentValue2");

					this.selectCodeExtraction(currentValue);
					
				}),
				currentValue3Change: Ember.observer("currentValue3",function(){

					var currentValue = this.get("currentValue3");

					this.selectCodeExtraction(currentValue);
					
				}),
				currentValue4Change: Ember.observer("currentValue4",function(){

					var currentValue = this.get("currentValue4");

					this.selectCodeExtraction(currentValue);
					
				}),
				currentValue5Change: Ember.observer("currentValue5",function(){

					var currentValue = this.get("currentValue5");

					this.selectCodeExtraction(currentValue);
					
				}),

				//desc的降序和升序的布尔值

				descGroup: {
					one:{
						"id":false,
						"successRate":false,
						"responseTime":false
					},
					two:{
						"id":false,
						"successRate":false,
						"responseTime":false
					},
					three:{
						"id":false,
						"successRate":false,
						"responseTime":false
					},
					four:{
						"id":false,
						"successRate":false,
						"responseTime":false
					},
					five:{
						"id":false,
						"successRate":false,
						"responseTime":false
					}
				},

				//排序desc字段的取反
				descTakeBack: function(num){
					var ctrl = this;
					if(ctrl.get("sortBy") != undefined){
						if(ctrl.get("descGroup")[num][ctrl.get("sortBy")]){

							Ember.set(ctrl.get("descGroup")[num],ctrl.get("sortBy"),false);
						}else{
							Ember.set(ctrl.get("descGroup")[num],ctrl.get("sortBy"),true);
						}
					};
				},


				//请求数据

				requireData: function(){
					var ctrl = this,
						serviceId = ctrl.get("model.id"),
						typeValue = ctrl.get("typeValue");
					var params = {
						"appId": this.get("business.id"),
						"typeName": this.get("typeName"),
						"channelName": this.get("channelName"),
						"dstIp": this.get("dstIp"),
						"srcIp": this.get("srcIp"),
						"responseCode": this.get("responseCode"),
					    "startDate": +this.get("startDate"),
						"endDate":  +this.get("endDate"),
						"pageIndex": this.get("pageIndex"),
					    "pageSize": this.get("pageTop"),
					    "groupBy": this.get('groupBy'),
					 	"sortBy": this.get("sortBy"),
						"desc": this.get("desc")
					};


					if( isLocalDebugModel ){
						params = undefined;
					}

					return this.store.ajax("GET", "trades/multiStatistic", params)
					.then(function(response){
						var result = response.result;
						var dimension = response.dimension;

						if(!result){
							return;
						}
						result.forEach(function(node,index){
							node.sequence = index+1;
							node.dimension = dimension;
						});

						if (result.length == 0) {
							ctrl.set("pageIndex",0);
							ctrl.set("pageSize",10);
							ctrl.set("totalRows",0);//设置为0显示没有数据
						} else {
							ctrl.set("pageIndex",response.meta.pageIndex);
							ctrl.set("pageSize",response.meta.pageSize);
							ctrl.set("totalRows",response.meta.total);
						}
						var newString = ctrl.saveString();
						switch(dimension){
							case 1:
							ctrl.set("oneString",newString);
							ctrl.descTakeBack("one");
							ctrl.set("oneContent",result);
							break;
							case 2:
							ctrl.set("twoString",newString);
							ctrl.descTakeBack("two");
							ctrl.set("twoContent",result);
							break;
							case 3:
							ctrl.set("threeString",newString);
							ctrl.descTakeBack("three");
							ctrl.set("threeContent",result);
							break;
							case 4:
							ctrl.set("fourString",newString);
							ctrl.descTakeBack("four");
							ctrl.set("fourContent",result);
							break;
							case 5:
							ctrl.set("fiveString",newString);
							ctrl.descTakeBack("five");
							ctrl.set("fiveContent",result);
							break;
						}
						
						ctrl.set("sortBy",undefined);
						return response;
					});
				},


				oneContent: Ember.A([]),
				twoContent: Ember.A([]),
				threeContent: Ember.A([]),
				fourContent: Ember.A([]),
				fiveContent: Ember.A([]),

				reset: function(){
					var ctrl = this;
					ctrl.set("miltListsShow.dimensionOne",false);
					ctrl.set("miltListsShow.dimensionTwo",false);
					ctrl.set("miltListsShow.dimensionThree",false);
					ctrl.set("miltListsShow.dimensionFour",false);
					ctrl.set("miltListsShow.dimensionFive",false);
					ctrl.set("miltListsShow.dimensionRadioTwo",false);
					ctrl.set("miltListsShow.dimensionRadioThree",false);
					ctrl.set("miltListsShow.dimensionRadioFour",false);
					ctrl.set("miltListsShow.dimensionRadioFive",false);
					ctrl.set("groupByArr",Ember.A([]));
					ctrl.set("backgroundField",Ember.A([]));
					ctrl.set("typeName","");
					ctrl.set("channelName","");
					ctrl.set("dstIp","");
					ctrl.set("srcIp","");
					ctrl.set("responseCode","");

				},

				resetGroupBy: function(dimension){
					var ctrl = this,
						backgroundField = ctrl.get("backgroundField");
						arr = ["channelName","dstIp","srcIp","responseCode","typeName"],
						newArr = [];

						backgroundField.forEach(function(node){
							arr = ctrl.filterGroup(arr,node);
						});
						arr.forEach(function(node){
							ctrl.set(node,undefined);
							
						});

				},

				filterGroup: function(arr,item){
					arr.forEach(function(node,index){
						if(node == item){
							arr.splice(index,1);
						}
					});
					return arr;
				},

				showRadio: function(num,boolean){
					var ctrl = this;
					if(num == 1){
						ctrl.set("miltListsShow.dimensionRadioTwo",false);
						ctrl.set("miltListsShow.dimensionRadioThree",false);
						ctrl.set("miltListsShow.dimensionRadioFour",false);
						ctrl.set("miltListsShow.dimensionRadioFive",false);
					}else if(num == 2){
						ctrl.set("miltListsShow.dimensionRadioTwo",boolean);
						ctrl.set("miltListsShow.dimensionRadioThree",false);
						ctrl.set("miltListsShow.dimensionRadioFour",false);
						ctrl.set("miltListsShow.dimensionRadioFive",false);
					}else if(num == 3){
						ctrl.set("miltListsShow.dimensionRadioThree",boolean);
						ctrl.set("miltListsShow.dimensionRadioFour",false);
						ctrl.set("miltListsShow.dimensionRadioFive",false);
					}else if(num == 4){
						ctrl.set("miltListsShow.dimensionRadioFour",boolean);
						ctrl.set("miltListsShow.dimensionRadioFive",false);
					}else if(num == 5){
						ctrl.set("miltListsShow.dimensionRadioFive",boolean);
					}
				},

				showColumns: function(num,hide){
					var ctrl = this;
					if(num == 1){
						if(!hide){
							ctrl.set("miltListsShow.dimensionOne",true);
						}
						ctrl.set("miltListsShow.dimensionTwo",false);
						ctrl.set("miltListsShow.dimensionThree",false);
						ctrl.set("miltListsShow.dimensionFour",false);
						ctrl.set("miltListsShow.dimensionFive",false);
						ctrl.set("oneContent", Ember.A([]));

					}else if(num == 2){
						if(!hide){
							ctrl.set("miltListsShow.dimensionTwo",true);
						}
						ctrl.set("miltListsShow.dimensionThree",false);
						ctrl.set("miltListsShow.dimensionFour",false);
						ctrl.set("miltListsShow.dimensionFive",false);
						ctrl.set("twoContent", Ember.A([]));
					}else if(num == 3){
						if(!hide){
							ctrl.set("miltListsShow.dimensionThree",true);
						}
						ctrl.set("miltListsShow.dimensionFour",false);
						ctrl.set("miltListsShow.dimensionFive",false);
						ctrl.set("threeContent", Ember.A([]));
					}else if(num == 4){
						if(!hide){
							ctrl.set("miltListsShow.dimensionFour",true);
						}
						ctrl.set("miltListsShow.dimensionFive",false);
						ctrl.set("fourContent", Ember.A([]));
					}else if(num == 5){
						if(!hide){
							ctrl.set("miltListsShow.dimensionFive",true);
						}
						ctrl.set("fiveContent", Ember.A([]));
					}
				},

				groupByArr: Ember.A([]),

				backgroundField: Ember.A([]),

				//通过字段来设置名称
				
				setNameByField: function(string){

					switch(string){
						case "typeName":
							name = "交易类型";
						break;
						case "channelName":
							name = "交易渠道";
						break;
						case "dstIp":
							name = "服务器IP";
						break;
						case "srcIp":
							name = "客户端IP";
						break;
						case "responseCode":
							name = "交易返回码";
						break;
					}
					return name;
				},

				radioPublicExtraction: function(num,serverity,certainValue){
					var ctrl = this,
						backgroundField = ctrl.get("backgroundField"),
						radioType = null;

					
					for(var name in certainValue){
						ctrl.set(name,certainValue[name]);
					}	

					radioType = serverity.substring(0,serverity.indexOf(num));

					ctrl.set("groupBy",radioType);
					ctrl.showRadio(parseInt(num),true);
					ctrl.showColumns(parseInt(num,false));

					backgroundField.splice(parseInt(num)-1,5);

					ctrl.resetGroupBy(parseInt(num)+1);
					backgroundField.pushObject(radioType);

					setTimeout(function(){
						var setNameByField = ctrl.setNameByField(radioType);
						$(".dimensionNum").eq(parseInt(num)-1).find("th").eq(1).find(".wijmo-wijgrid-headertext").html(setNameByField);
					},1);

					switch(parseInt(num)){
							case 1:
								var radioType = serverity.substring(0,serverity.indexOf(1));
								var newObject = Ember.merge(ctrl.get("objectBase"),{"groupBy":radioType});
								ctrl.setString(newObject);
								ctrl.set("oneString1",newObject);
								ctrl.set("index",1);
							break;
							case 2:
								var radioType = serverity.substring(0,serverity.indexOf(2));
								var base = ctrl.get("oneString1"),
									newSelectObject = ctrl.get("newSelectObject"),
									index = ctrl.get("index");

									if(index <= 2){
										var json = ctrl.filterJson(base);

										var newBase = Ember.merge(json,newSelectObject);
										Ember.merge(newBase,{"groupBy":radioType});
										ctrl.set("twoString1",newBase);
										ctrl.setString(newBase);
										ctrl.set("index",2);
									}else{
										var twoString = ctrl.get("twoString1");
										Ember.merge(twoString,{"groupBy":radioType});
										ctrl.setString(twoString);
									}
			
							break;
							case 3:
								var radioType = serverity.substring(0,serverity.indexOf(3));
								var base = ctrl.get("twoString1"),
									newSelectObject = ctrl.get("newSelectObject"),
									index = ctrl.get("index");

									if(index <= 3){
										var json = ctrl.filterJson(base);

										var newBase = Ember.merge(json,newSelectObject);
										Ember.merge(newBase,{"groupBy":radioType});
										ctrl.set("threeString1",newBase);
										ctrl.setString(newBase);
										ctrl.set("index",3);
									}else{
										var twoString = ctrl.get("threeString1");
										Ember.merge(twoString,{"groupBy":radioType});
										ctrl.setString(twoString);
									}
								
							break;
							case 4:
								var radioType = serverity.substring(0,serverity.indexOf(4));
								var base = ctrl.get("threeString1"),
									newSelectObject = ctrl.get("newSelectObject"),
									index = ctrl.get("index");

									if(index <= 4){
										var json = ctrl.filterJson(base);

										var newBase = Ember.merge(json,newSelectObject);
										Ember.merge(newBase,{"groupBy":radioType});
										ctrl.set("fourString1",newBase);
										ctrl.setString(newBase);
										ctrl.set("index",4);
									}else{
										var twoString = ctrl.get("fourString1");
										Ember.merge(twoString,{"groupBy":radioType});
										ctrl.setString(twoString);
									}
								
							break;
							case 5:
								var radioType = serverity.substring(0,serverity.indexOf(5));
								var base = ctrl.get("fourString1"),
									newSelectObject = ctrl.get("newSelectObject"),
									index = ctrl.get("index");

									if(index <= 5){
										var json = ctrl.filterJson(base);

										var newBase = Ember.merge(json,newSelectObject);
										Ember.merge(newBase,{"groupBy":radioType});
										ctrl.set("fiveString1",newBase);
										ctrl.setString(newBase);
										ctrl.set("index",5);
									}else{
										var twoString = ctrl.get("fiveString1");
										Ember.merge(twoString,{"groupBy":radioType});
										ctrl.setString(twoString);
									}
								
							break;
						}
					
					this.requireData();
				},

				stringDimensional: {
					"oneDimensionalField": {},
					"twoDimensionalField": {},
					"threeDimensionalField": {},
					"fourDimensionalField": {},
					"fiveDimensionalField": {},
				},
				
				//保存每一个维度的字段
				saveString: function(){
					var object = {}
					object["typeName"] = this.get("typeName")||"";
					object["channelName"] = this.get("channelName")||"";
					object["dstIp"] = this.get("dstIp")||"";
					object["srcIp"] = this.get("srcIp")||"";
					object["responseCode"] = this.get("responseCode")||"";
					object["groupBy"] = this.get("groupBy")||"";
					return object;
				},

				allString: {
					"typeName": "",
					"channelName": "",
					"dstIp": "",
					"srcIp": "",
					"responseCode": ""
				},

				hideRadio: function(dimension){
					var ctrl = this;
					switch(dimension){
						case 2:
							ctrl.set("miltListsShow.dimensionRadioTwo",false);
						break;
						case 3:
							ctrl.set("miltListsShow.dimensionRadioThree",false);
						break;
						case 4:
							ctrl.set("miltListsShow.dimensionRadioFour",false);
						break;
						case 5:
							ctrl.set("miltListsShow.dimensionRadioFive",false);
						break;
						

					}	
				},

				//给每个维度字段改变某值
				filterStringToChang: function(dimension,string,value){
					var ctrl = this;
					switch(dimension){
						case 2:
							if(!ctrl.get("twoString"))return;
							ctrl.get("twoString")[string] = value
						break;
						case 3:
							if(!ctrl.get("threeString"))return;
							ctrl.get("threeString")[string] = value
						break;
						case 4:
							if(!ctrl.get("fourString"))return;
							ctrl.get("fourString")[string] = value
						break;
						case 5:
							if(!ctrl.get("fiveString"))return;
							ctrl.get("fiveString")[string] = value
						break;
					}
				},
				//过滤对象得到新的对象脱离跟上面一个对象的关系
				filterJson: function(base){

					var json = {};
					for(var name in base){
						json[name] = base[name];	
					}
					return json
				},
				oneTop1:undefined,

				actions: {
					miltListsShow: {
						"dimensionFour": true,
						"dimensionOne": true,
						"dimensionTwo": true,
						"dimensionThree": true,
					},

					export: function(index){

						var appId = this.get("business.id"),
							typeName = null,
							channelName = null,
							dstIp = null,
							srcIp = null,
							responseCode = null,
							groupBy = null,
					    	startDate = +this.get("startDate"),
							endDate = +this.get("endDate"),
							ctrl = this,
							json = null,
							pageSize = this.get("pageTop"),
							sortBy = this.get("sortBy"),
							desc = this.get("desc");

						switch(index){
							case 1:
								json = ctrl.get("oneString1");
							break;
							case 2:
								json = ctrl.get("twoString1");
							break;
							case 3:
								json = ctrl.get("threeString1");
							break;
							case 4:
								json = ctrl.get("fourString1");
							break;
							case 5:
								json = ctrl.get("fiveString1");
							break;
						}

						for(var name in json){
							if(name == "typeName"){
								typeName = json[name];
							}else if(name == "channelName"){
								channelName = json[name];
							}else if(name == "dstIp"){
								dstIp = json[name];
							}else if(name == "responseCode"){
								responseCode =  json[name];
							}else if(name == "srcIp"){
								srcIp = json[name];
							}else if(name == "groupBy"){
								groupBy = json[name];
							}
						}
						var url="/front/rest/apm/trades/downloadMultiStatistic?groupBy="+groupBy+"&appId="+appId+"&desc="+desc+"&sortBy="+sortBy+"&typeName="+typeName+"&channelName="+channelName+"&dstIp="+dstIp+"&srcIp="+srcIp+"&responseCode="+responseCode+"&startDate="+startDate+"&endDate="+endDate+"&token="+encodeURIComponent($.cookie("token"));

						if(pageSize){
							url +="&pageSize="+pageSize;
						};

						confirmDialog("确定要导出表格吗？")
						.then(function(){
							window.location.href =url;
						});
					},

					itemClick: function(serverity){

						var ctrl = this;
						var multColumns = ctrl.get("multColumns"),
							index = null,
							certainValue = ctrl.get("certainValue");

						ctrl.set("shieldingWithSavedData",true);
						ctrl.set("pageTop",10);

						if(serverity.indexOf('1') != -1){
							$(".dimension-menu-down-pos").eq(0).addClass("dimension-menu-up").removeClass("dimension-menu-down");
							$(".show-hide").eq(0).removeClass("dimensional-hide");
							ctrl.set("oneTop1",true);
							ctrl.set("currentValue1","oneTop10");
							ctrl.radioPublicExtraction('1',serverity,certainValue);
							index = 1;	
						}else if(serverity.indexOf('2') != -1){	
							$(".dimension-menu-down-pos").eq(0).removeClass("dimension-menu-up").addClass("dimension-menu-down");
								$(".show-hide").eq(0).addClass("dimensional-hide");
							$(".dimension-menu-down-pos").eq(1).addClass("dimension-menu-up").removeClass("dimension-menu-down");
							$(".show-hide").eq(1).removeClass("dimensional-hide");
							ctrl.set("oneTop2",true);
							ctrl.set("currentValue2","twoTop10");	
							ctrl.radioPublicExtraction('2',serverity,certainValue);		
							index = 2;
						}else if(serverity.indexOf('3') != -1){	
							for(var i=0;i<2;i++){
								$(".dimension-menu-down-pos").eq(i).removeClass("dimension-menu-up").addClass("dimension-menu-down");
								$(".show-hide").eq(i).addClass("dimensional-hide");
							}
							$(".dimension-menu-down-pos").eq(2).addClass("dimension-menu-up").removeClass("dimension-menu-down");
							$(".show-hide").eq(2).removeClass("dimensional-hide");
							ctrl.set("oneTop3",true);
							ctrl.set("currentValue3","threeTop10");
							ctrl.radioPublicExtraction('3',serverity,certainValue);
							
							index = 3;
						}else if(serverity.indexOf('4') != -1){
							for(var i=0;i<3;i++){
								$(".dimension-menu-down-pos").eq(i).removeClass("dimension-menu-up").addClass("dimension-menu-down");
								$(".show-hide").eq(i).addClass("dimensional-hide");
							}
							$(".dimension-menu-down-pos").eq(3).addClass("dimension-menu-up").removeClass("dimension-menu-down");
							$(".show-hide").eq(3).removeClass("dimensional-hide");
							ctrl.set("oneTop4",true);
							ctrl.set("currentValue4","fourTop10");
							ctrl.radioPublicExtraction('4',serverity,certainValue);
							
							index = 4;
						}else if(serverity.indexOf('5') != -1){
							for(var i=0;i<4;i++){
								$(".dimension-menu-down-pos").eq(i).removeClass("dimension-menu-up").addClass("dimension-menu-down");
								$(".show-hide").eq(i).addClass("dimensional-hide");
							}
							
						
							$(".dimension-menu-down-pos").eq(4).addClass("dimension-menu-up").removeClass("dimension-menu-down");
							$(".show-hide").eq(4).removeClass("dimensional-hide");
							ctrl.set("oneTop5",true);
							ctrl.set("currentValue5","fiveTop10");
							ctrl.radioPublicExtraction('5',serverity,certainValue);
							
							index = 5;
						}

						switch(index){
							case 1:

								if(ctrl.get("oneString")){	
									ctrl.set("stringDimensional.oneDimensionalField",ctrl.get("oneString1"));
								}else{
									var object = ctrl.saveString();
									ctrl.set("stringDimensional.oneDimensionalField",object);	
								}
							break;
							case 2:

								if(ctrl.get("oneString")){	
									ctrl.set("stringDimensional.twoDimensionalField",ctrl.get("oneString"));
								}else{
									var object = ctrl.saveString();
									ctrl.set("stringDimensional.twoDimensionalField",object);	
								}
			
							break;
							case 3:

								if(ctrl.get("oneString")){	
									ctrl.set("stringDimensional.threeDimensionalField",ctrl.get("oneString"));
								}else{
									var object = ctrl.saveString();
									ctrl.set("stringDimensional.threeDimensionalField",object);	
								}
								
							break;
							case 4:

								if(ctrl.get("oneString")){	
									ctrl.set("stringDimensional.fourDimensionalField",ctrl.get("oneString"));
								}else{
									var object = ctrl.saveString();
									ctrl.set("stringDimensional.fourDimensionalField",object);	
								}
								
							break;
							case 5:

								if(ctrl.get("oneString")){	
									ctrl.set("stringDimensional.fiveDimensionalField",ctrl.get("oneString"));
								}else{
									var object = ctrl.saveString();
									ctrl.set("stringDimensional.fiveDimensionalField",object);	
								}
								
							break;
						}
						ctrl.set("shieldingWithSavedData",false);

						setTimeout(function(){
							ctrl.set("changeString",false);
						},0);
						

						
						
					},

					gridSorted: function(e, data, view){
						view.ensureControl(false);
						var dataKey = data.column.dataKey;
						this.set("orderBy", dataKey);
						this.set("desc", data.sortDirection=="descending"||undefined);
						this.requireData();
					},


					gridCellClicked: function(e, args, view){
						var ctrl = this,
							row = args.cell.row(),
							dynamicRadio = [],
							dynamicAllRadio = this.get("dynamicAllRadio"),
							column = args.cell.column(),
							groupByArr = ctrl.get("groupByArr");

						// ctrl.set("oneDesc",true);

						// if(ctrl.get("oldString")){
						// 	//回复排序之前的字段
						// 	ctrl.setString(ctrl.get("oldString"));
						// }


						if (row && (row.type & $.wijmo.wijgrid.rowType.data)) {

							var dimension = row.data.dimension+1;
							if(column.dataKey == "typeName"){
								var data = row.data,
									allString = ctrl.get("allString");
								
								ctrl.set("resetPageSize",true);

								ctrl.set("certainValue",{});

								if(data["channelName"]){

									ctrl.set("newSelectObject",{"channelName":row.data.channelName});

									ctrl.set("groupBy","channelName");
								}else if(data["responseCode"]){

									ctrl.set("newSelectObject",{"responseCode":row.data.responseCode});

									ctrl.set("groupBy","responseCode");
								}else if(data["dstIp"]){
									
									ctrl.set("newSelectObject",{"dstIp":row.data.dstIp});

									ctrl.set("groupBy","dstIp");
								}else if(data["srcIp"]){
									
									ctrl.set("newSelectObject",{"srcIp":row.data.srcIp})

									ctrl.set("groupBy","srcIp");
								}else if(data["typeName"]){
									
									ctrl.set("newSelectObject",{"typeName":row.data.typeName})

									ctrl.set("groupBy","typeName");
								}
								
								//单选框通过维度和已经选过的来显示和隐藏
								switch(dimension){
									case 2:
										groupByArr[0] = ctrl.get("groupBy");
										groupByArr.splice(1,5);
										ctrl.set("index",2);
										ctrl.set("miltListsShow.dimensionTwo",false);
										ctrl.set("miltListsShow.dimensionThree",false);
										ctrl.set("miltListsShow.dimensionFour",false);
										ctrl.set("miltListsShow.dimensionFive",false);
										if($(".dimensionNum").eq(1).find(".dynamic-radio input").length != 0){
											$(".dimensionNum").eq(1).find(".dynamic-radio input").attr("checked",false);
										}
									break;
									case 3:
										groupByArr[1] = ctrl.get("groupBy");
										groupByArr.splice(2,5);
										ctrl.set("index",3);
										ctrl.set("miltListsShow.dimensionThree",false);
										ctrl.set("miltListsShow.dimensionFour",false);
										ctrl.set("miltListsShow.dimensionFive",false);
										if($(".dimensionNum").eq(2).find(".dynamic-radio input").length != 0){
											$(".dimensionNum").eq(2).find(".dynamic-radio input").attr("checked",false);
										}
									break;
									case 4:
										groupByArr[2] = ctrl.get("groupBy");
										groupByArr.splice(3,5);
										ctrl.set("index",4);
										ctrl.set("miltListsShow.dimensionFour",false);
										ctrl.set("miltListsShow.dimensionFive",false);
										if($(".dimensionNum").eq(3).find(".dynamic-radio input").length != 0){
											$(".dimensionNum").eq(3).find(".dynamic-radio input").attr("checked",false);
										}
									break;
									case 5:
										groupByArr[3] = ctrl.get("groupBy");
										groupByArr.splice(4,5);
										ctrl.set("index",5);
										ctrl.set("miltListsShow.dimensionFive",false);
										if($(".dimensionNum").eq(4).find(".dynamic-radio input").length != 0){
											$(".dimensionNum").eq(4).find(".dynamic-radio input").attr("checked",false);
										}
									break;
								}

								switch(this.get("groupBy")){
									case "typeName":
										this.hideRadio(dimension);
										setTimeout(function(){
											ctrl.showRadio(dimension,true);	
										},10);
										
										ctrl.set("typeName",row.data.typeName);
										
										ctrl.filterStringToChang(dimension,"typeName",row.data.typeName);
										
										//当前某一个字段的值
										ctrl.set("certainValue",{"typeName":row.data.typeName});
										allString["typeName"] = row.data.typeName;
									break;
									case "channelName":
										this.hideRadio(dimension);
										setTimeout(function(){
											ctrl.showRadio(dimension,true);	
										},10);
										ctrl.set("channelName",row.data.channelName);
										ctrl.filterStringToChang(dimension,"channelName",row.data.channelName);
										
										//当前某一个字段的值
										ctrl.set("certainValue",{"channelName":row.data.channelName})
										allString["channelName"] = row.data.channelName;
									break;
									case "dstIp":
										this.hideRadio(dimension);
										setTimeout(function(){
											ctrl.showRadio(dimension,true);	
										},10);
										ctrl.set("dstIp",row.data.dstIp);
										ctrl.filterStringToChang(dimension,"dstIp",row.data.dstIp);
										
										//当前某一个字段的值
										ctrl.set("certainValue",{"dstIp":row.data.dstIp});
										allString["dstIp"] = row.data.dstIp;
									case "srcIp":
										this.hideRadio(dimension);
										setTimeout(function(){
											ctrl.showRadio(dimension,true);	
										},10);
										ctrl.set("srcIp",row.data.srcIp);
										ctrl.filterStringToChang(dimension,"srcIp",row.data.srcIp);
										
										//当前某一个字段的值
										ctrl.set("certainValue",{"srcIp":row.data.srcIp});
										allString["srcIp"] = row.data.srcIp;
									break;
									case "responseCode":
										this.hideRadio(dimension);
										setTimeout(function(){
											ctrl.showRadio(dimension,true);	
										},10);
										ctrl.set("responseCode",row.data.responseCode);
										ctrl.filterStringToChang(dimension,"responseCode",row.data.responseCode);
										
										//当前某一个字段的值
										ctrl.set("certainValue",{"responseCode":row.data.responseCode});
										allString["responseCode"] = row.data.responseCode;
									break;
								}
								ctrl.set("allString",allString);
							}
						}
					},
					timePointChange: function(timeRange){
						this.set("startDate",timeRange.startDate);
						this.set("endDate",timeRange.endDate);
						if($(".dimensionNum").eq(0).find(".dynamic-radio input").length != 0){
							$(".dimensionNum").eq(0).find(".dynamic-radio input").attr("checked",false);
						}
						this.set("desc",true);
						this.reset();
						this.requireData();
					},
					menuDown: function(num){
						if($(".dimension-menu-down-pos").eq(num-1).hasClass("dimension-menu-up")){
							$(".dimension-menu-down-pos").eq(num-1).addClass("dimension-menu-down").removeClass("dimension-menu-up");
						}else{
							$(".dimension-menu-down-pos").eq(num-1).addClass("dimension-menu-up").removeClass("dimension-menu-down");
						}
						$(".show-hide").eq(num-1).toggleClass("dimensional-hide");
					},
					timeRangesChange: function(timeRange){
						var ctrl = this;
						var pinTimePoint = ctrl.get("controllers.businessDetail").pinTimePoint;
						that = this;
							ctrl.set("startDate", timeRange.startDate);
							ctrl.set("endDate", timeRange.endDate);
				
		
						// var view = Broada.getView("businessTimeRangesTopo");
						if(ctrl.get("pinTimePoint") != (timeRange.startDate)){
							ctrl.set("pinTimePoint", null);
						}

						// if(timeRange.selectVal == "n1M"||timeRange.selectVal == "n1d"){
						// 	ctrl.set("startDate", timeRange.startDate);
						// 	ctrl.set("endDate", timeRange.endDate);
						// };

						if($(".dimensionNum").eq(0).find(".dynamic-radio input").length != 0){
							$(".dimensionNum").eq(0).find(".dynamic-radio input").attr("checked",false);
						}
						ctrl.set("desc",true);
						ctrl.reset();
						ctrl.requireData();
					}
				}
			});

		APM.BusinessDetailNodedetailMultidimensionalController = Controller;
		return Controller;
	}
);
